package com.zt.questionnaire.common.utils;

import org.apache.commons.lang3.StringUtils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class TimeUtils {
    /**
     * 一分钟多少秒
     **/
    public static long MINUTE = 60;// 分钟

    /**
     * 半个小多少秒
     **/
    public static long MINUTE_30 = 30 * MINUTE;

    /**
     * 一小时多少秒
     **/
    public static long HOUR = 60 * MINUTE;// 小时

    /**
     * 一天多少秒
     **/
    public static long DAY = 24 * HOUR;// 天

    /**
     * 一周
     **/
    public static long WEEK = 7 * DAY;

    /**
     * 半个月多少秒
     **/
    public static long DAY_15 = 15 * DAY;// 天
    /**
     * 一个月多少秒
     **/
    public static long DAY_30 = 30 * DAY;// 天
    /**
     * 十五分钟
     **/
    public static long MIN_15 = 15 * MINUTE; // 分钟

    /**
     * 格式化 时间格式：yyyy-MM-dd -》 2021-02-02 12:20:20
     */
    public static final String PATTERN_DATE = "yyyy-MM-dd";
    /**
     * 格式化 时间格式：yyyy-MM-dd HH:mm:ss -》 2021-02-02 12:20:20
     */
    public static final String PATTERN_DATE_TIME = "yyyy-MM-dd HH:mm:ss";

    /**
     * 说明：把long类型的时间转换成Date的指定类型
     *
     * @param time
     * @return
     */
    public static Date longToDate(long time) {
        if (time <= 0) {
            return null;
        }
        return new Date(time);
    }

    public static long dateToLong(Date time) {
        if (time == null) {
            return 0;
        }
        return time.getTime();
    }

    public static String timeToStringFromat(long time, String fromat) {
        Date d = longToDate(time);
        return dateToString(d, fromat);
    }

    /**
     * 说明：将匹配一定模式的String型的时间转换成java.util.Date型
     *
     * @param dateString String型日期
     * @param parse      匹配模式,希望格式化后的时间格式
     * @return 返回一个日期
     */
    public static Date stringToDate(String dateString, String format) {
        SimpleDateFormat sdf = new SimpleDateFormat(format);
        Date date = null;
        try {
            date = sdf.parse(dateString);
        } catch (ParseException e) {
            e.printStackTrace();
            // log.error("String to Date error");
            // 打印日志
        }
        return date;
    }

    /**
     * 获取类似2012-01-01的日期格式
     *
     * @param time
     * @return
     */
    public static String longToYear_Month_Day(long time) {
        Date d = longToDate(time);
        if (d == null) {
            return null;
        }
        return dateToString(d, "yyyy-MM-dd");
    }

    /**
     * 获取类似20120101的日期格式
     *
     * @param time
     * @return
     */
    public static String longToYearMonthDay(long time) {
        Date d = longToDate(time);
        if (d == null) {
            return null;
        }
        return dateToString(d, "yyyyMMdd");
    }

    public static String longToMin(long time) {
        Date d = longToDate(time);
        if (d == null) {
            return null;
        }
        return dateToString(d, "yyyy-MM-dd HH:mm:ss");
    }

    public static String longToYearMonth(long time) {
        Date d = longToDate(time);
        if (d == null) {
            return null;
        }
        return dateToString(d, "yyyyMM");
    }

    /**
     * 毫秒转换为“年月日时分秒”的格式
     *
     * @param time
     * @return
     */
    public static String longToYearMonthDayHourMinSecon(long time) {
        Date d = longToDate(time);
        if (d == null) {
            return null;
        }
        return dateToString(d, "yyyyMMddHHmmss");
    }

    /**
     * 获取年周时间(周是指一年中的第几周)
     *
     * @param time
     * @return
     */
    public static int longToYearWeek(long time) {
        Calendar obj = Calendar.getInstance();
        obj.setTimeInMillis(time);
        int year = obj.get(Calendar.YEAR);
        int week = obj.get(Calendar.WEEK_OF_YEAR);
        if (week < 10) {
            return Integer.parseInt(year + "0" + week);
        } else {
            return Integer.parseInt(year + "" + week);
        }
    }

    public static int longToYearDay(long time) {
        Calendar obj = Calendar.getInstance();
        obj.setTimeInMillis(time);
        int year = obj.get(Calendar.YEAR);
        int day = obj.get(Calendar.DAY_OF_YEAR);
        if (day < 10) {
            return Integer.parseInt(year + "0" + day);
        } else {
            return Integer.parseInt(year + "" + day);
        }
    }

    public static String longToString(long time) {
        Date d = longToDate(time);
        return dateToString(d);
    }

    /**
     * long -> 日期字符串
     * @param time 时间戳
     * @param pattern 格式 TimeUtils.PATTERN_ 开头
     * @return
     */
    public static String longToString(long time, String pattern) {
        Date d = longToDate(time);
        return dateToString(d, pattern);
    }

    /**
     * 说明：字符串类型转换成日期(包含时间,格式yyyy-MM-dd HH:mm:ss)
     *
     * @param String
     * @return Date date
     */
    public static Date stringToDate(String dateString) {
        return stringToDate(dateString, "yyyy-MM-dd HH:mm:ss");
    }

    public static String dateToString(Date date, String format) {
        SimpleDateFormat sdfFull = new SimpleDateFormat(format);
        return sdfFull.format(date);
    }

    /**
     * 说明：日期类型转换成字符串(包含时间,格式yyyy-MM-dd HH:mm:ss)
     *
     * @param Date date
     * @return String
     */
    public static String dateToString(Date date) {
        return dateToString(date, "yyyy-MM-dd HH:mm:ss");
    }

    public static Calendar stringToCalendar(String dateString, String format) {
        Calendar calendar = Calendar.getInstance();
        try {
            SimpleDateFormat sdf = new SimpleDateFormat(format);
            Date date = sdf.parse(dateString);
            calendar.setTime(date);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return calendar;
    }

    private static Calendar getCalendar(int year, int month, int day, int hour, int minute, int second) {
        Calendar calendar = Calendar.getInstance();
        if (year >= 0) {
            calendar.set(Calendar.YEAR, year);
        }
        if (month >= 0) {
            calendar.set(Calendar.MONTH, month - 1); // 从0开始
        }
        if (day >= 0) {
            calendar.set(Calendar.DAY_OF_MONTH, day);
        }
        if (hour >= 0) {
            calendar.set(Calendar.HOUR_OF_DAY, hour); // 从1开始，有24(24点表示0点)或者就是0点到23点
        }
        if (minute >= 0) {
            calendar.set(Calendar.MINUTE, minute);
        }
        if (second >= 0) {
            calendar.set(Calendar.SECOND, second);
        }
        calendar.set(Calendar.MILLISECOND, 0);
        return calendar;
    }

    /**
     * 获取毫秒，指定常规年月日时分秒时间
     *
     * @param year   年，负数表示本年
     * @param month  月，负数表示本月
     * @param day    日，负数表示本日
     * @param hour   从1开始，有24(24点表示0点)或者就是0点到23点，负数表示当天小时
     * @param minute
     * @param second
     * @return
     */
    public static long getTime(int year, int month, int day, int hour, int minute, int second) {
        Calendar calendar = getCalendar(year, month, day, hour, minute, second);
        return calendar.getTimeInMillis();
    }

    public static Date getDate(int year, int month, int day, int hour, int minute, int second) {
        Calendar calendar = getCalendar(year, month, day, hour, minute, second);
        return calendar.getTime();
    }

    /**
     * 获取今天某个时间点的时间
     *
     * @param hour   从1开始，有24(24点表示0点)或者就是0点到23点
     * @param minute
     * @param second
     * @return
     */
    public static Date getDate(int hour, int minute, int second) {
        Calendar calendar = getCalendar(-1, -1, -1, hour, minute, second);
        return calendar.getTime();
    }

    /**
     * 获取每日起始结束时间
     *
     * @param time
     * @return
     */
    public static long[] getHourStartEndTime(long time) {
        return getHourStartEndTime(time, 0);
    }

    /**
     * 获取某小时的起始时间
     *
     * @param time       某小时的任意时间点
     * @param offsetTime 偏移时间
     * @return
     */
    public static long[] getHourStartEndTime(long time, int offsetTime) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTimeInMillis(time - offsetTime);
        calendar.set(Calendar.MINUTE, 0);
        calendar.set(Calendar.SECOND, 0);
        calendar.set(Calendar.MILLISECOND, 0);
        long start = calendar.getTimeInMillis();
        long end = start + 60 * 60 * 1000 - 1000;
        return new long[]{start, end};
    }

    public static long[] getDayStartEndTime(long time) {
        return getDayStartEndTime(time, 0);
    }

    /**
     * 获取当天的开始时间戳 00:00:00
     *
     * @return
     */
    public static long getDayStartTime() {
        return getDayStartEndTime(getCurrTime())[0];
    }

    /**
     * 获取当天的结束时间戳 23:59:59
     *
     * @return
     */
    public static long getDayEndTime() {
        return getDayStartEndTime(getCurrTime())[1];
    }

    /**
     * 获取某天的起始时间
     *
     * @param time       某天的任意时间点
     * @param offsetTime 偏移时间
     * @return
     */
    public static long[] getDayStartEndTime(long time, int offsetTime) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTimeInMillis(time - offsetTime);
        calendar.set(Calendar.HOUR_OF_DAY, 0); // 从1开始，有24(24点表示0点)或者就是0点到23点
        calendar.set(Calendar.MINUTE, 0);
        calendar.set(Calendar.SECOND, 0);
        calendar.set(Calendar.MILLISECOND, 0);
        long start = calendar.getTimeInMillis();
        long end = start + 24 * 60 * 60 * 1000 - 1000;
        return new long[]{start, end};
    }

    /**
     * 获取当前点的时间戳
     *
     * @param hour 几点
     * @return
     */
    public static long getTimeStamp(Integer hour) {
        Calendar calendar = Calendar.getInstance();
        long currTime = TimeUtils.getCurrTime();
        calendar.setTimeInMillis(currTime - 0);
        calendar.set(Calendar.HOUR_OF_DAY, hour); // 从1开始，有24(24点表示0点)或者就是0点到23点
        calendar.set(Calendar.MINUTE, 0);
        calendar.set(Calendar.SECOND, 0);
        calendar.set(Calendar.MILLISECOND, 0);
        return calendar.getTimeInMillis();
    }

    /**
     * 获取最近几天的时间(在原有的时间基础上减去某个的时间)
     *
     * @param time
     * @param day  天数
     * @return
     */
    public static long[] getRecentlyDayStartEndTime(long time, int day) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTimeInMillis(time);
        calendar.add(Calendar.DAY_OF_YEAR, -day);
        long start = calendar.getTimeInMillis();
        long end = getDayStartEndTime(time)[1];
        return new long[]{start, end};
    }

    /**
     * 获取最近几月的时间(在原有的时间基础上减去某个的时间),包含当月
     *
     * @param time
     * @param month 月数
     * @return
     */
    public static long[] getRecentlyMonthStartEndTime(Long time, int month) {
        if (time == null) {
            time = TimeUtils.getCurrTime();
        }
        month = month - 1;
        Calendar calendar = Calendar.getInstance();
        calendar.setTimeInMillis(time);
        calendar.add(Calendar.MONTH, -month);
        calendar.set(Calendar.DAY_OF_MONTH, 1);
        calendar.set(Calendar.HOUR_OF_DAY, 0); // 从1开始，有24(24点表示0点)或者就是0点到23点
        calendar.set(Calendar.MINUTE, 0);
        calendar.set(Calendar.SECOND, 0);
        calendar.set(Calendar.MILLISECOND, 0);

        long start = calendar.getTimeInMillis();
        long end = getMonthStartEndTime(time)[1];
        return new long[]{start, end};
    }

    /**
     * 获取今天某个时间点的时间
     *
     * @param hour   从1开始，有24(24点表示0点)或者就是0点到23点
     * @param minute
     * @param second
     * @return
     */
    public static Date getTime(int hour, int minute, int second) {
        Calendar calendar = Calendar.getInstance();
        calendar.set(Calendar.HOUR_OF_DAY, hour); // 从1开始，有24(24点表示0点)或者就是0点到23点
        calendar.set(Calendar.MINUTE, minute);
        calendar.set(Calendar.SECOND, second);
        calendar.set(Calendar.MILLISECOND, 0);
        return calendar.getTime();
    }

    /**
     * 获取今天开始的时间，0点时点0分
     *
     * @return
     */
    public static long getTodayStartTime() {
        Calendar calendar = Calendar.getInstance();
        calendar.set(Calendar.HOUR_OF_DAY, 0);
        calendar.set(Calendar.MINUTE, 0);
        calendar.set(Calendar.SECOND, 0);
        calendar.set(Calendar.MILLISECOND, 0);
        return calendar.getTimeInMillis();
    }

    /**
     * 返回指定毫秒的时间点的，年月日时分秒值
     *
     * @param millisecond
     * @return
     */
    public static int[] getTimes(long millisecond) {
        Calendar cal = Calendar.getInstance();
        cal.setTimeInMillis(millisecond);
        int year = cal.get(Calendar.YEAR);
        int month = cal.get(Calendar.MONTH);
        int day = cal.get(Calendar.DAY_OF_MONTH);
        int hours = cal.get(Calendar.HOUR_OF_DAY);
        int minute = cal.get(Calendar.MINUTE);
        int second = cal.get(Calendar.SECOND);
        int[] time = {year, month, day, hours, minute, second};
        return time;
    }

    public static int getYear(Date d) {
        Calendar cal = Calendar.getInstance();
        cal.setTime(d);
        int year = cal.get(Calendar.YEAR);
        return year;
    }

    public static int getYear(long millisecond) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTimeInMillis(millisecond);
        int year = calendar.get(Calendar.YEAR);
        return year;
    }

    /**
     * 获取当前年份
     *
     * @return
     */
    public static int getYear() {
        Calendar calendar = Calendar.getInstance();
        return calendar.get(Calendar.YEAR);
    }

    /**
     * 当前当前是几月份(1-12，已经转换过的月份)
     *
     * @return
     */
    public static int getMonth() {
        Calendar calendar = Calendar.getInstance();
        return calendar.get(Calendar.MONTH) + 1;
    }

    public static int getMonth(long millisecond) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTimeInMillis(millisecond);
        return calendar.get(Calendar.MONTH) + 1;
    }

    //获取当天小时

    /**
     * 获取月的起始时间
     *
     * @param time null=当前月
     * @return
     */
    public static long[] getMonthStartEndTime(Long time) {
        if (time == null) {
            time = getCurrTime();
        }
        return getMonthStartEndTime(time, 0);
    }

    /**
     * 获取某天的起始时间
     *
     * @param time       某天的任意时间点
     * @param offsetTime 偏移时间
     * @return
     */
    public static long[] getMonthStartEndTime(long time, int offsetTime) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTimeInMillis(time - offsetTime);
        calendar.set(Calendar.DAY_OF_MONTH, 1);
        calendar.set(Calendar.HOUR_OF_DAY, 0); // 从1开始，有24(24点表示0点)或者就是0点到23点
        calendar.set(Calendar.MINUTE, 0);
        calendar.set(Calendar.SECOND, 0);
        calendar.set(Calendar.MILLISECOND, 0);

        long MaxDay = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
        long start = calendar.getTimeInMillis();
        long end = start + MaxDay * DAY * 1000 - 1000;
        return new long[]{start, end};
    }

    public static long[] getYearStartEndTime(long time) {
        return getYearStartEndTime(time, 0);
    }

    public static long[] getYearStartEndTime(long time, int offsetTime) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTimeInMillis(time - offsetTime);
        calendar.set(Calendar.DAY_OF_YEAR, 1);
        calendar.set(Calendar.HOUR_OF_DAY, 0); // 从1开始，有24(24点表示0点)或者就是0点到23点
        calendar.set(Calendar.MINUTE, 0);
        calendar.set(Calendar.SECOND, 0);
        calendar.set(Calendar.MILLISECOND, 0);

        long MaxDay = calendar.getActualMaximum(Calendar.DAY_OF_YEAR);
        long start = calendar.getTimeInMillis();
        long end = start + MaxDay * DAY * 1000 - 1000;
        return new long[]{start, end};
    }

    /**
     * 获取一年最大的天数（365或366）
     *
     * @param time
     * @return
     */
    public static int getMaxDayOfYear() {
        Calendar calendar = Calendar.getInstance();
        int maxDay = calendar.getActualMaximum(Calendar.DAY_OF_YEAR);
        return maxDay;
    }

    /**
     * 获取一年最大的天数（365或366）
     *
     * @param time
     * @return
     */
    public static int getMaxDayOfYear(long time) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTimeInMillis(time);
        int maxDay = calendar.getActualMaximum(Calendar.DAY_OF_YEAR);
        return maxDay;
    }

    /**
     * 获取当前天，今天是这个月的第几天
     *
     * @return
     */
    public static int getDayOfMonth() {
        Calendar calendar = Calendar.getInstance();
        return calendar.get(Calendar.DAY_OF_MONTH);
    }

    public static int getDayOfMonth(long millisecond) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTimeInMillis(millisecond);
        return calendar.get(Calendar.DAY_OF_MONTH);
    }

    // public static int getMaxDayOfMonth(long time){
    // Date d = new Date(time);
    // Calendar cal = Calendar.getInstance();
    // cal.setTime(d);
    // cal.get(Calendar.)
    //
    // }

    /**
     * 获取当前是一年中的第几天
     *
     * @return
     */
    public static int getDayOfYear() {
        Calendar calendar = Calendar.getInstance();
        return calendar.get(Calendar.DAY_OF_YEAR);
    }

    public static int getDayOfYear(long time) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTimeInMillis(time);
        return calendar.get(Calendar.DAY_OF_YEAR);
    }

    /**
     * 获取当前是几点
     *
     * @return
     */
    public static int getHourOfDay() {
        Calendar calendar = Calendar.getInstance();
        return calendar.get(Calendar.HOUR_OF_DAY);
    }

    public static int getHourOfDay(long millisecond) {
        Date d = new Date(millisecond);
        Calendar cal = Calendar.getInstance();
        cal.setTime(d);
        return cal.get(Calendar.HOUR_OF_DAY);
    }

    public static int getDayOfWeek(long millisecond) {
        Date d = new Date(millisecond);
        Calendar cal = Calendar.getInstance();
        cal.setTime(d);
        int dw = cal.get(Calendar.DAY_OF_WEEK) - 1;

        if (dw == 0) {
            dw = 7;
        }
        return dw;
    }

    /**
     * 获取当前是周几（1—7表示星期一到星期天）
     *
     * @return
     */
    public static int getDayOfWeek() {
        Calendar calendar = Calendar.getInstance();
        int week = calendar.get(Calendar.DAY_OF_WEEK) - 1;
        if (week == 0) {
            week = 7;
        }
        return week;
    }

    /*
     * public static void main(String[] args) { System.out.println(getWeekOfYear());
     * long time1 = getCurrTime() - (3 * 24+15) * 60 * 60 * 1000 ; long time2 =
     * time1 + 9 * 60 * 60 * 1000 ; boolean sameWeek = isSameWeek(time1, time2,
     * 8*60*60*1000); System.out.println(sameWeek);
     * System.out.println(longToString(time1));
     * System.out.println(longToString(time2));
     * System.out.println(longToString(baseTime)); long currTime = getCurrTime();
     * System.out.println(isSameMonth(currTime, currTime-9*60*60*1000,
     * 8*60*60*1000)); System.out.println(longToYearMonthDay(1454860800000L));
     *
     * long currTime2 = TimeUtils.getCurrTime(); System.out.println(currTime2);
     * long[] weekStartEndTimeByBaseTime = getWeekStartEndTimeByBaseTime(currTime2);
     * System.out.println(longToYearMonthDay(weekStartEndTimeByBaseTime[0])+","+
     * longToYearMonthDay(weekStartEndTimeByBaseTime[1]));
     * weekStartEndTimeByBaseTime =
     * getWeekStartEndTimeByBaseTime(currTime2,OGlobal.offset_time_week);
     * System.out.println(longToYearMonthDay(weekStartEndTimeByBaseTime[0])+","+
     * longToYearMonthDay(weekStartEndTimeByBaseTime[1]));
     *
     * System.out.println(longToYearMonthDay(TimeUtils.getTime(-1, -1, 1, 0, 0,
     * 0))); System.out.println(longToYearMonthDay(1461420000000L));
     *
     * System.out.println(longToYearMonth(1461420000000L)); //
     * System.out.println(getDayStartEndTime(currTime)[0]); //
     * System.out.println(currTime-15*60*60*1000-24*60*1000); //
     * System.out.println(getTime(1, 0, 0).getTime()); //
     * System.out.println(getTodayStartTime()); }
     * System.out.println(longToString1(TimeUtils.getTime(-1, -1, 1, 0, 0, 0)));
     * System.out.println(longToString1(1460201700000L)); }
     */

    /**
     * 获取当前是一个月中的第几周
     *
     * @return
     */
    public static int getWeekOfMonth() {
        Calendar calendar = Calendar.getInstance();
        int week = calendar.get(Calendar.WEEK_OF_MONTH);
        return week;
    }

    /**
     * 获取当前是一年中的第几周
     *
     * @return
     */
    public static int getWeekOfYear() {
        Calendar calendar = Calendar.getInstance();
        int week = calendar.get(Calendar.WEEK_OF_YEAR);
        return week;
    }

    public static int getWeekOfYear(long time) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTimeInMillis(time);
        int week = calendar.get(Calendar.WEEK_OF_YEAR);
        return week;
    }

    /**
     * 获取指定周期类型里的毫秒转换成系统的毫秒数
     *
     * @param timeType 周期类型。“日”= 一天内第几毫秒，“周”= 一周内(周一到周日)第几毫秒，“时” = 一小时内第几毫秒
     * @param ms       周期类型里的毫秒数
     * @return
     */
    public static long getTime(String timeType, long ms) {
        Calendar cal = Calendar.getInstance();
        if (timeType.equals("日")) {
            // time表示一天中的第几毫秒
            cal.set(Calendar.HOUR_OF_DAY, 0);
            cal.set(Calendar.MINUTE, 0);
            cal.set(Calendar.SECOND, 0);
            cal.set(Calendar.MILLISECOND, (int) ms);

        } else if (timeType.equals("周")) {
            // time表示一周中的第几毫秒,设置一周中第二天，实际上是我们平时概念里的周一
            cal.set(Calendar.DAY_OF_WEEK, 2);
            cal.set(Calendar.HOUR_OF_DAY, 0);
            cal.set(Calendar.MINUTE, 0);
            cal.set(Calendar.SECOND, 0);
            cal.set(Calendar.MILLISECOND, (int) ms);
        } else if (timeType.equals("时")) {
            // time表示一小时中的第几毫秒
            cal.set(Calendar.MINUTE, 0);
            cal.set(Calendar.SECOND, 0);
            cal.set(Calendar.MILLISECOND, (int) ms);
        }
        long time = cal.getTimeInMillis();
        return time;
    }

    /**
     * 获取当前月份最大天数
     *
     * @return
     */
    public static int getMaxDayOfMonth() {
        Calendar cal = Calendar.getInstance();
        int day = cal.getActualMaximum(Calendar.DATE);
        return day;
    }

    /**
     * 获取一月最大的天数（28或29或30或31）
     *
     * @param milliSecond 毫秒
     * @return
     */
    public static int getMaxDayOfMonth(long milliSecond) {
        Calendar cal = Calendar.getInstance();
        cal.setTimeInMillis(milliSecond);
        int day = cal.getActualMaximum(Calendar.DATE);
        return day;
    }

    /**
     * 获取指定时间月份最大天数
     *
     * @param month 月
     * @return
     */
    public static int getMaxDayOfMonth(int month) {
        Calendar cal = Calendar.getInstance();
        cal.set(Calendar.MONTH, month - 1);
        int day = cal.getActualMaximum(Calendar.DATE);
        return day;
    }

    /**
     * 时间从begin_time开始算起，有效时间是seconds秒，判断当前时间是否超过有效时间
     *
     * @param begin_time 形式 如:2008-9-11 23:58:00
     * @param seconds    秒
     * @return 返回true表示超过有效时间，false表示没有超过有效时间
     */
    public static boolean isOverdue(Date begin_time, int seconds) {
        boolean result = true;
        if (begin_time == null) {
            return true;
        }
        if (seconds == 0) {
            return true;
        }
        // 当前时间
        Calendar current_time = Calendar.getInstance();
        // 当前时间之前的seconds秒的有效时间
        current_time.add(Calendar.SECOND, -seconds);
        Date effect_time = current_time.getTime();
        // 判断开始时间是否在有效时间之前，如果在有效时间之前则表示已当前时间已超过开始时间seconds秒返回false
        if (begin_time.before(effect_time)) {
            result = true;
        } else {
            result = false;
        }
        return result;
    }

    /**
     * 时间从beginTime开始算起加month个月
     *
     * @param beginTime null表示以当前时间为起始时间
     * @param month
     * @return
     */
    public static long addMonth(Long beginTime, int month) {
        Calendar c = Calendar.getInstance();
        if (beginTime != null) {
            c.setTimeInMillis(beginTime);
        }
        c.add(Calendar.MONTH, month);
        return c.getTimeInMillis();
    }

    /**
     * 时间从begin_time开始算起加day天数
     *
     * @param begin_time
     * @param day
     * @return
     */
    public static Date addDay(Date begin_time, int day) {
        GregorianCalendar cal = new GregorianCalendar();
        cal.setTime(begin_time);
        cal.add(Calendar.DAY_OF_YEAR, day);
        Date d = cal.getTime();
        return d;
    }

    /**
     * 时间从begin_time开始算起加hour小时
     *
     * @param begin_time
     * @param hour
     * @return
     */
    public static Date addHour(Date begin_time, int hour) {
        GregorianCalendar cal = new GregorianCalendar();
        cal.setTime(begin_time);
        cal.add(Calendar.HOUR, hour);
        Date d = cal.getTime();
        return d;
    }


    /**
     * 获取固定的某天的起始时间
     *
     * @param day 某天 ，1： 1号
     * @return
     */
    public static long getFixedTime(Date time, int day) {
        GregorianCalendar cal = new GregorianCalendar();
        if (time != null) {
            cal.setTime(time);
        }
        cal.set(Calendar.DAY_OF_MONTH, 0);
        cal.add(Calendar.DAY_OF_MONTH, day);
        cal.set(Calendar.HOUR_OF_DAY, 0);
        cal.set(Calendar.MINUTE, 0);
        cal.set(Calendar.SECOND, 0);
        cal.set(Calendar.MILLISECOND, 0);
        return cal.getTimeInMillis();
    }

    /**
     * 获取某月的某天开始到某天结束 1-5时间戳
     *
     * @param time
     * @param startDay
     * @param endDay
     * @return
     */
    public static long[] getIntervalTime(Date time, int startDay, int endDay) {
        Calendar cal = Calendar.getInstance();
        Calendar cal2 = Calendar.getInstance();
        if (time != null) {
            cal.setTime(time);
            cal2.setTime(time);
        }
        cal.set(Calendar.DAY_OF_MONTH, 0);
        cal.add(Calendar.DAY_OF_MONTH, startDay);
        cal.set(Calendar.HOUR_OF_DAY, 0);
        cal.set(Calendar.MINUTE, 0);
        cal.set(Calendar.SECOND, 0);
        cal.set(Calendar.MILLISECOND, 0);
        cal2.set(Calendar.DAY_OF_MONTH, 0);
        cal2.add(Calendar.DAY_OF_MONTH, endDay);
        cal2.set(Calendar.HOUR_OF_DAY, 23);
        cal2.set(Calendar.MINUTE, 59);
        cal2.set(Calendar.SECOND, 59);
        cal2.set(Calendar.MILLISECOND, 999);
        return new long[]{cal.getTimeInMillis(), cal2.getTimeInMillis()};
    }

    /**
     * 时间从begin_time开始算起加minute分钟
     *
     * @param begin_time
     * @param minute
     * @return
     */
    public static Date addMinute(Date begin_time, int minute) {
        GregorianCalendar cal = new GregorianCalendar();
        cal.setTime(begin_time);
        cal.add(Calendar.MINUTE, minute);
        Date d = cal.getTime();
        return d;
    }

    // 1970年1月5日是周一，这里算是否是同一周只指周一到周日7天为一个单位，这个时间在同一个项目里一旦定下来了就不能改动了，否则会造成拿不到数据
    private static long baseTime = getTime(2016, 2, 8, 0, 0, 0);
    private static long one_week_second = 7 * 24 * 60 * 60 * 1000;

    /**
     * 是否是同一周，时间是从本周一的零点到周日的23点59分59秒
     *
     * @param time1
     * @param time2
     * @return
     */
    public static boolean isSameWeek(long time1, long time2) {
        return isSameWeek(time1, time2, 0);
    }

    /**
     * 是否是同一周
     *
     * @param time1
     * @param time2
     * @param offsetTime 偏移时间（毫秒），当偏移时间为0的时候，默认时间是从本周一的零点到周日的23点59分59秒，如果是要从周二零点算一周的开始，
     *                   偏移时间就为24小时的毫秒数，其他类推
     * @return
     */
    public static boolean isSameWeek(long time1, long time2, int offsetTime) {
        int n1 = getWeekByBaseTime(time1, offsetTime);
        int n2 = getWeekByBaseTime(time2, offsetTime);
        if (n1 == n2) {
            return true;
        }
        return false;
    }

    /**
     * 获取现在是第几周，从基础时间开始算起的（周一的零点为一周的开始）
     *
     * @param time
     * @return
     */
    public static int getWeekByBaseTime(long time) {
        return getWeekByBaseTime(time, 0);
    }

    /**
     * 获取现在是第几周，从基础时间开始算起的
     *
     * @param time
     * @param offsetTime 偏移时间（毫秒），当偏移时间为0的时候，默认时间是从本周一的零点到周日的23点59分59秒，如果是要从周二零点算一周的开始，便宜时间就为24小时的毫秒数，其他类推
     * @return
     */
    public static int getWeekByBaseTime(long time, int offsetTime) {
        long base = baseTime + offsetTime;
        long value = time - base;
        if (value <= 0) {
            return 1;
        }
        int n = (int) (value / one_week_second);
        return n + 1;
    }

    /**
     * 获取某周的起始时间
     *
     * @param week 第几周，根据基准时间算出来的第几周
     * @return
     */
    public static long[] getWeekStartEndTimeByBaseTime(int week, int offsetTime) {
        long base = baseTime + offsetTime;
        long start = base + (week - 1) * one_week_second;
        long end = start + one_week_second - 1000;
        return new long[]{start, end};
    }

    /**
     * 获取某周的起始时间
     *
     * @param time 某周中的任意时间，null=当前时间
     * @return
     */
    public static long[] getWeekStartEndTimeByBaseTime(Long time) {
        if (time == null) {
            time = getCurrTime();
        }
        int week = getWeekByBaseTime(time);
        return getWeekStartEndTimeByBaseTime(week, 0);
    }

    /**
     * 获取某周的起始时间
     *
     * @param time       某周中的任意时间
     * @param offsetTime 偏移时间
     * @return
     */
    public static long[] getWeekStartEndTimeByBaseTime(long time, int offsetTime) {
        int week = getWeekByBaseTime(time, offsetTime);
        return getWeekStartEndTimeByBaseTime(week, offsetTime);
    }

    public static boolean isSameDay(long time1, long time2) {
        if (time1 == time2) {
            return true;
        }
        Calendar cal1 = Calendar.getInstance();
        cal1.setTimeInMillis(time1);

        Calendar cal2 = Calendar.getInstance();
        cal2.setTimeInMillis(time2);

        if (cal1.get(Calendar.YEAR) == cal2.get(Calendar.YEAR)
                && cal1.get(Calendar.DAY_OF_YEAR) == cal2.get(Calendar.DAY_OF_YEAR)) {
            return true;
        }
        return false;
    }

    public static boolean isSameDay(long time1, long time2, int offsetTime) {
        return isSameDay(time1 - offsetTime, time2 - offsetTime);
    }

    /**
     * 获取两个时间是否为同一天
     *
     * @param d1
     * @param d2
     * @return
     */
    public static boolean isSameDay(Date d1, Date d2) {
        SimpleDateFormat fmt = new SimpleDateFormat("yyyyMMdd");
        return fmt.format(d1).equals(fmt.format(d2));
    }

    /**
     * 判断当前时间是否与compare_time在同一天
     *
     * @param compare_time
     * @return
     */
    public static boolean isSameDay(Date compare_time) {
        if (compare_time == null) {
            return false;
        }
        boolean isSameDay = false;
        // 当前时间
        Calendar current_time = Calendar.getInstance();
        int current_year = current_time.get(Calendar.YEAR);
        int current_day_of_year = current_time.get(Calendar.DAY_OF_YEAR);

        Calendar compare_datetime = Calendar.getInstance();
        compare_datetime.setTime(compare_time);
        int compare_year = compare_datetime.get(Calendar.YEAR);
        int compare__day_of_year = compare_datetime.get(Calendar.DAY_OF_YEAR);

        if (current_year == compare_year && current_day_of_year == compare__day_of_year) {
            isSameDay = true;
        }
        return isSameDay;
    }

    public static boolean isSameMonth(long time1, long time2) {
        if (time1 == time2) {
            return true;
        }
        Calendar cal1 = Calendar.getInstance();
        cal1.setTimeInMillis(time1);

        Calendar cal2 = Calendar.getInstance();
        cal2.setTimeInMillis(time2);

        if (cal1.get(Calendar.YEAR) == cal2.get(Calendar.YEAR)
                && cal1.get(Calendar.MONTH) == cal2.get(Calendar.MONTH)) {
            return true;
        }
        return false;
    }


    public static boolean isSameMonth(long time1, long time2, int offsetTime) {
        return isSameMonth(time1 - offsetTime, time2 - offsetTime);
    }

    /**
     * 判断当前时间是否与compare_time在同一个月
     *
     * @param compare_time
     * @return
     */
    public static boolean isSameMonth(Date compare_time) {
        if (compare_time == null) {
            return false;
        }
        boolean isSameMonth = false;
        // 当前时间
        Calendar current_time = Calendar.getInstance();
        int current_year = current_time.get(Calendar.YEAR);
        int current_month_of_year = current_time.get(Calendar.MONTH);

        Calendar compare_datetime = Calendar.getInstance();
        compare_datetime.setTime(compare_time);
        int compare_year = compare_datetime.get(Calendar.YEAR);
        int compare__month_of_year = compare_datetime.get(Calendar.MONTH);

        if (current_year == compare_year && current_month_of_year == compare__month_of_year) {
            isSameMonth = true;
        }
        return isSameMonth;
    }

    /**
     * 将java Date时间转换为unix时间戳
     *
     * @return
     */
    public static String TimeDate2Stamp() {
        String unixDate = null;
        try {
            /*
             * Timestamp appointTime=Timestamp.valueOf(new
             * SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date())); SimpleDateFormat
             * df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); Date date =
             * df.parse(String.valueOf(appointTime)); long s=date.getTime();
             * unixDate=String.valueOf(s).substring(0, 10);
             */

            unixDate = String.valueOf(System.currentTimeMillis() / 1000);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return unixDate;
    }

    /**
     * 将unix时间戳转换为java Date
     *
     * @param timestampString
     * @param formats
     * @return
     */
    public static String TimeStamp2Date(String timestampString) {
        Long timestamp = Long.parseLong(timestampString) * 1000;
        String date = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date(timestamp));
        return date;
    }

    /**
     * 比较日期返回天数
     *
     * @param begin_time
     * @param end_time
     * @return
     */
    public static int getDifferDaysByDate(Date begin_time, Date end_time) {
        Date begin_times = formatDate((begin_time), "yyyy-MM-dd");
        Date end_timea = formatDate((end_time), "yyyy-MM-dd");
        int days = 0;
        days = (int) ((end_timea.getTime() - begin_times.getTime()) / (DAY * 1000));
        return days;
    }

    /**
     * 根据pattern格式化date
     *
     * @param date
     * @param pattern 形式如"yyyy-MM-dd"
     * @return
     */
    public static Date formatDate(Date date, String pattern) {
        if (date == null || pattern == null) {
            return date;
        }
        Date new_date = null;

        SimpleDateFormat f = new SimpleDateFormat(pattern);

        String date_str = f.format(date);

        try {
            new_date = f.parse(date_str);
        } catch (ParseException e) {
            e.printStackTrace();
        }

        return new_date;
    }

    public static long getCurrTime() {
        return System.currentTimeMillis();
    }

    /**
     * 获取当前时间,格式为 "yyyy-MM-dd HH:mm:ss"
     *
     * @return
     */
    public static String getCurrTimes() {
        Date d = new Date();
        String time = dateToString(d);
        return time;
    }

    /**
     * 判断主方法
     */
    public static boolean validate(String dateString) {
        // 使用正则表达式 测试 字符 符合 dddd-dd-dd 的格式(d表示数字)
        Pattern p = Pattern.compile("\\d{4}+[-]\\d{1,2}+[-]\\d{1,2}+");
        Matcher m = p.matcher(dateString);
        if (!m.matches()) {
            return false;
        }

        // 得到年月日
        String[] array = dateString.split("-");
        int year = Integer.valueOf(array[0]);
        int month = Integer.valueOf(array[1]);
        int day = Integer.valueOf(array[2]);

        if (month < 1 || month > 12) {
            return false;
        }
        int[] monthLengths = new int[]{0, 31, -1, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
        if (isLeapYear(year)) {
            monthLengths[2] = 29;
        } else {
            monthLengths[2] = 28;
        }
        int monthLength = monthLengths[month];
        if (day < 1 || day > monthLength) {
            return false;
        }
        return true;
    }

    /**
     * 获取给定日期字符串指定的当天起始时间的毫秒数
     *
     * @return
     */
    public static long getDayStart(String dateStr) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Long time = null;
        try {
            Date date = sdf.parse(dateStr);
            time = date.getTime();
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return time;
    }

    /**
     * 获取当天的日期字符串，格式："yyyy-MM-dd"
     *
     * @return
     */
    public static String getDayStr() {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        return sdf.format(new Date());
    }

    /**
     * 获取当月的日期字符串，格式："yyyy-MM-dd"
     *
     * @return
     */
    public static String getMonthStr(String pattern) {
        if (StringUtils.isBlank(pattern)) {
            pattern = "yyyyMM";
        }
        SimpleDateFormat sdf = new SimpleDateFormat(pattern);
        return sdf.format(new Date());
    }

    /**
     * 获取当天的起始时间的毫秒数
     *
     * @return
     */
    public static long getDayTime() {
        Date date = new Date();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        String format = sdf.format(date);
        try {
            date = sdf.parse(format);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return date.getTime();
    }

    /**
     * 是否是闰年
     */
    private static boolean isLeapYear(int year) {
        return ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0);
    }

    // 根据日期取得星期几
    public static String getWeek(Date date) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd EEEE");
        String week = sdf.format(date);
        return week;
    }
    public static long stringToLong(String timeStr, String format) {
        AssertUtils.isBlank(timeStr, "time is null");
        AssertUtils.isBlank(format, "format is null");
        Date date = stringToDate(timeStr, format);
        return date.getTime();
    }
    public static void main(String[] args) {

        long custom1 = stringToLong("2022-12-01 23:23:59", PATTERN_DATE_TIME);
        System.out.println(custom1);

        System.out.println(getTodayStartTime());

        System.out.println(longToString(1665367000201L));

        System.out.println("longToString1 ===> " + timeToStringFromat(1630484680793L, "yyyy-MM-dd HH:mm:ss"));

        System.out.println(getCurrTime());
        System.out.println(getDayStartEndTime(getCurrTime())[0]);
        System.out.println(getMonthStartEndTime(getCurrTime())[0]);

        Date date1 = addHour(new Date(getDayStartEndTime(getCurrTime())[0]), 7);


        long[] hourStartEndTime = getHourStartEndTime(getCurrTime());

        long threeTimeEnd = TimeUtils.getMonthStartEndTime(TimeUtils.addMonth(getCurrTime(), 2))[1];
        System.out.println(getCurrTime());
        long ll1 = stringToDate("2023-01-03 00:00:00", "yyyy-MM-dd HH:mm:ss").getTime();
        long ll2 = stringToDate("2023-01-10 23:59:59", "yyyy-MM-dd HH:mm:ss").getTime();
        long ll3 = stringToDate("2021-06-14 00:00:00", "yyyy-MM-dd HH:mm:ss").getTime();
        System.out.println("红包开始 1 ===> " + ll1 + "_" + timeToStringFromat(ll1, "yyyy-MM-dd HH:mm:ss"));
        System.out.println("红包结束 1 ===> " + ll2 + "_" + timeToStringFromat(ll2, "yyyy-MM-dd HH:mm:ss"));
        System.out.println(" 红包开始 1 ===> " + ll3 + "_" + timeToStringFromat(ll3, "yyyy-MM-dd HH:mm:ss"));

        long[] times = TimeUtils.getRecentlyMonthStartEndTime(null, 3);
        long timeStart = times[0];
        long timeEnd = times[1];
        long t = 1614528000000L - 60L * 60 * 1000;
        System.out.println("longToString2 ===> " + timeToStringFromat(1627032034239L, "yyyy-MM-dd HH:mm:ss"));
        System.out.println("longToString2 ===> " + timeToStringFromat(1627032034108L, "yyyy-MM-dd HH:mm:ss"));

        System.out.println("longToString1 ===> " + timeToStringFromat(1626969600000L, "yyyy-MM-dd HH:mm:ss"));
        System.out.println("longToString1 ===> " + timeToStringFromat(TimeUtils.getMonthStartEndTime(t)[1], "yyyy-MM-dd HH:mm:ss"));

        System.out.println("longToString1 ===> " + timeToStringFromat(1614528000000L, "yyyy-MM-dd HH:mm:ss"));
        System.out.println("longToString2 ===> " + timeToStringFromat(1609430400000L, "yyyy-MM-dd HH:mm:ss"));
        System.out.println(getCurrTime());
        System.out.println(getMonthStartTime());
        String longToYearMonthDayHourMinSecon = TimeUtils.longToYearMonthDayHourMinSecon(TimeUtils.getCurrTime());
        System.out.println(longToYearMonthDayHourMinSecon);

        long[] recentlyMonthStartEndTime = getRecentlyMonthStartEndTime(null, 3);
        System.out.println("day---> " + recentlyMonthStartEndTime[0] + timeToStringFromat(recentlyMonthStartEndTime[0], "yyyy年MM月dd日 HH:mm:ss"));
        System.out.println("day---> " + recentlyMonthStartEndTime[1] + timeToStringFromat(recentlyMonthStartEndTime[1], "yyyy年MM月dd日 HH:mm:ss"));

        long[] recentlyDayStartEndTime = getRecentlyDayStartEndTime(addDay(new Date(), -7).getTime(), 6);
        System.out.println(recentlyDayStartEndTime[0] + "-" + recentlyDayStartEndTime[1]);
        Integer day = 15 - 1;
        long time6 = TimeUtils.addDay(new Date(1610347353643L), day).getTime();
        System.out.println("red_packet---" + time6);
        System.out.println("timeToString ===> " + timeToStringFromat(time6, "yyyy年MM月dd日 HH:mm:ss"));


        long endT = getMonthStartEndTime(1609405469384L)[1];

        long start = getDayStartEndTime(addDay(new Date(), 0).getTime())[0];
        long end = getDayStartEndTime(addDay(new Date(), 0).getTime())[1];

        System.out.println("longToString1 ===> " + start + "_" + timeToStringFromat(start, "yyyy-MM-dd HH:mm:ss"));
        System.out.println("longToString2 ===> " + end + "_" + timeToStringFromat(end, "yyyy-MM-dd HH:mm:ss"));

        System.out.println("addDay ===> " + getDayStartEndTime(addDay(new Date(), 0).getTime())[0]);
        System.out.println("addDay ===> " + getDayStartEndTime(addDay(new Date(), 0).getTime())[1]);
        System.out.println("============================================================================");
        long monthStart = getMonthStartEndTime(addMonth(getCurrTime(), -2))[0];
        long monthEnd = getMonthStartEndTime(addMonth(getCurrTime(), -2))[1];
        System.out.println("addMonth ===> " + monthStart + "_" +
                timeToStringFromat(monthStart, "yyyy年MM月dd日 HH:mm:ss"));
        System.out.println("addMonth ===> " + monthEnd + "_" +
                timeToStringFromat(monthEnd, "yyyy年MM月dd日 HH:mm:ss") );
        System.out.println();
        System.out.println("stringToDate 1 ===> " + stringToDate("2021-02-28 05:00:00", "yyyy-MM-dd HH:mm:ss").getTime());
        System.out.println("stringToDate 2 ===> " + stringToDate("2021-02-24 23:59:59", "yyyy-MM-dd HH:mm:ss").getTime());


        long[] days = TimeUtils.getDayStartEndTime(1600877800000L);

        System.out.println("timeToString ===> " + timeToStringFromat(stringToDate("2021-01-14 00:00:00", "yyyy-MM-dd HH:mm:ss").getTime(), "yyyy年MM月dd日 HH:mm:ss"));
        System.out.println("timeToString ===> " + timeToStringFromat(1622476800000L, "yyyy年MM月dd日 HH:mm:ss"));

        System.out.println("day---> " + days[0] + timeToStringFromat(1610606362469L, "yyyy年MM月dd日 HH:mm:ss"));
        System.out.println("day---> " + days[1] + timeToStringFromat(1614231306273L, "yyyy年MM月dd日 HH:mm:ss"));

        long[] months = TimeUtils.getMonthStartEndTime(TimeUtils.addMonth(getCurrTime(), 1));

        System.out.println(months[0] + timeToStringFromat(months[0], "yyyy年MM月dd日"));
        System.out.println(months[1] + timeToStringFromat(months[1], "yyyy年MM月dd日"));

        long[] dayStartEndTime = getRecentlyDayStartEndTime(TimeUtils.addDay(new Date(), 0).getTime(), 6);

        System.out.println(dayStartEndTime[0] + timeToStringFromat(dayStartEndTime[0], "yyyy年MM月dd日 HH:mm:ss"));
        System.out.println(dayStartEndTime[1] + timeToStringFromat(dayStartEndTime[1], "yyyy年MM月dd日 HH:mm:ss"));

        long currTime = TimeUtils.getCurrTime();
//		long start = TimeUtils.DAY_30 * 1000;

//		System.out.println("t: " + (currTime - start));
//		System.out.println("cur: " + currTime);
//
//		System.out.println("sss=" + TimeUtils.dateToString(new Date(), "yyyyMMddHHmmss"));

        // long time = getTime("日", 24*60*60*1000);
        //
        // System.out.println(new Date());
        // System.out.println(new Date(time));
        // System.out.println();
        // long a= 1331049600000L - 24*60*60*1000;
        // long b =1329926400000L;
        // System.out.println(new Date(a));
        // System.out.println(new Date(b));

        // 获取一个月的第一周的星期一
        Calendar cal = Calendar.getInstance();
        // 设置一年中的第几个月，0-11
        cal.set(Calendar.MONTH, 1);
        // 设置一个月的第几周，1开始
        cal.set(Calendar.WEEK_OF_MONTH, 3);
        // 设置一个一个周的星期几，1-7表示7-6
        cal.set(Calendar.DAY_OF_WEEK, 7);

        System.out.println(cal.get(Calendar.WEEK_OF_MONTH));
        System.out.println(new Date(cal.getTimeInMillis()));
        System.out.println(longToYearWeek(getCurrTime()));
        System.out.println(longToYearMonthDay(1462505022023L));
        System.out.println(longToString(1465585200000L));
        System.out.println(getCurrTime() - (long) 7 * 24 * 60 * 60 * 1000);
        System.out.println("=====");
        System.out.println(longToString(1465568900928L));
        System.out.println(longToString(1465568901391L));
        System.out.println(longToString(1465568902750L));
        System.out.println(longToString(1465585200000L));
        System.out.println(longToString(636252816829573456L));

        Calendar calendar = Calendar.getInstance();
        long MaxDay = calendar.getActualMaximum(Calendar.DAY_OF_YEAR);
        System.out.println(MaxDay);
        long[] yearStartEndTime = getYearStartEndTime(getCurrTime());
        System.out.println(longToString(yearStartEndTime[0]));
        System.out.println(longToString(yearStartEndTime[1]));

        Calendar c = Calendar.getInstance();
        c.add(Calendar.MONTH, 2);
        System.out.println(longToString(c.getTimeInMillis()));

        long time = getTime(2019, 4, 8, 8, 0, 0);
        long time1 = getTime(2019, 1, 4, 16, 0, 0);
        System.out.println(time);
        System.out.println(time1);
        Date formatDate = formatDate((new Date(1517377923168L)), "yyyy-MM-dd");
        System.out.println(longToString(1550120138396L));
        System.out.println(getCurrTime());

        Date date = getDate(2020, 2, 31, 5, 0, 0);
        System.out.println(getMonth(date.getTime()));
        System.out.println(getDayOfMonth(date.getTime()));

        System.out.println(getDayOfWeek());
    }

    public static Long getMonthStartTime() {
        return getMonthStartEndTime(getCurrTime())[0];
    }

    public static Long getMonthEndTime() {
        return getMonthStartEndTime(getCurrTime())[1];
    }

}
